# -*- coding: utf-8 -*-
"""
Flask 示例应用程序：用户登录表单
"""
from flask import Flask, request

app = Flask(__name__)

@app.route("/", methods=["GET", "POST"])
def home():
    """
    主页路由，返回简单的欢迎信息。
    """
    return "<h1>Hello, world</h1>"

@app.route("/signin", methods=["GET"])
def signin_form():
    """
    登录表单页面，返回一个 HTML 表单。
    """
    return """
    <form action="/signin" method="post">
        <p><input name="username" placeholder="Username"></p>
        <p><input name="password" type="password" placeholder="Password"></p>
        <p><button type="submit">Sign In</button></p>
    </form>
    """

@app.route("/signin", methods=["POST"])
def signin():
    """
    处理用户登录请求。
    验证用户名和密码是否正确，返回相应的消息。
    """
    username = request.form.get("username")
    password = request.form.get("password")

    if username == "admin" and password == "password":
        return "<h3>Hello, admin!</h3>"
    return "<h3>Bad username or password.</h3>"

if __name__ == "__main__":
    app.run(debug=True)